//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { Image as VanImage } from "vant";
import { scrollMixin } from "utils/mixin";
export default {
  name: "",
  //import引入的组件需要注入到对象中才能使用
  components: {
    VanImage
  },
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      userInfo: {},
      tabList: [
        {
          name: "分红明细",
          status: ""
        }
      ],
      shareList:[],
      status: "",
      page: 1,
      isLoadMore: true,
      total_page: 0,
      recordList: []
    };
  },
  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合
  methods: {
    ontabClick(event) {
      this.page = 1;
      this.getRewardsList();
    },
    getRewardsList() {
      let query = {
        page: this.page,
      };
      $http.post("plugin.ranking-dividend.frontend.controllers.center.rewards", query, "加载中..").then(response => {
        if (response.result == 1) {
          let res = response.data;
          let shareList = res.list.data;
          this.isLoadMore = true;
          this.total_page = res.list.last_page;
          if (!this.total_page) {
            this.page = 0;
          }
          this.shareList = shareList;
          this.userInfo = res.info;
          this.userInfo.all_amount = Number(this.userInfo.all_amount).toFixed(2) || '0.00';
        } else {
          this.$dialog.alert({
            message: response.msg
          });
        }
      });
    },
    //获取更多数据
    getMoreData() {
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        let query = {
          page: this.page
        };
        $http.post("plugin.ranking-dividend.frontend.controllers.center.rewards", query, "加载中").then(
          res => {
            this.isLoadMore = true;
            if (res.result === 1) {
              let data = res.data;
              let shareList = data.list.data;
              this.shareList = [...this.shareList, ...shareList]; //数组拼接
            } else {
              this.page = this.page - 1;
              this.isLoadMore = false;
            }
          },
          function(response) {
            console.log("response", response);
            // error callback
          }
        );
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getRewardsList();
  }
};
